package admin

import (
	"github.com/gin-gonic/gin"
	"jwgin/model/mysql"
	"jwgin/service"
)

type rabcrole struct {
}

func (l *rabcrole) Routers(Router *gin.RouterGroup) (R gin.IRoutes) {
	Router.GET("route/role", l.get)
	Router.PUT("route/role", l.put)
	Router.POST("route/role", l.post)
	Router.DELETE("route/role", l.del)
	return R
}

func (rabcrole) get(c *gin.Context) {
	resp := []mysql.Roles{}
	service.G.Find(&resp)
	RespSucc(c, resp)
}
func (rabcrole) put(c *gin.Context) {
	requ := &mysql.Roles{}
	if err := c.ShouldBind(requ); err != nil {
		RespErr(c, err)
		return
	}
	service.G.Create(requ)
	service.CasbinLoad()
	RespSucc(c, nil)
}
func (rabcrole) post(c *gin.Context) {
	requ := &mysql.Roles{}
	if err := c.ShouldBind(requ); err != nil {
		RespErr(c, err)
		return
	}
	service.G.Where("rule_id = ?", requ.RuleId).Updates(requ)
	service.CasbinLoad()
	RespSucc(c, nil)
}
func (rabcrole) del(c *gin.Context) {}
